$(document).ready(function(){
    $("#province_id").change(function(){
	var city_id = $("#city_id");
	var town_id = $("#town_id");
	$("#city_code").val($(this).val());
	$.post(
	    "/region/get-cities",
	    {province_code: $(this).val()},
	    function (data)
	    {		
		city_id.children().remove();
		town_id.children().remove();
		city_id.append("<option value=''>所有城市</option>");
		$.each(
		    data, 
		    function(i, row)
		    {
			city_id.append("<option value='"+i+"'>"+row+"</option>");
		    }
		);
	    },
	    "json"
	);
    });
    $("#city_id").change(function(){
	var city_id = $("#city_id");
	var town_id = $("#town_id");
	$("#city_code").val($(this).val());
	$.post(
	    "/region/get-towns",
	    {city_code: $(this).val()},
	    function (data)
	    {		
		// city_id.children().remove();
		town_id.children().remove();
		town_id.append("<option value=''>所有区县</option>");
		$.each(
		    data, 
		    function(i, row)
		    {
			town_id.append("<option value='"+i+"'>"+row+"</option>");
		    }
		);
	    },
	    "json"
	);
    });
    $("#town_id").change(function(){
	$("#city_code").val($(this).val());
    });
});